#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <map> 

#define flr(x, l, r) for (int x = l; x <= r; ++x)
#define frl(x, r, l) for (int x = r; x >= l; --x)
#define fmp(x, t) for (int x = h[t]; ~x; x = ne[x])
#define LL long long
#define mt memset
#define my memcpy
#define szf sizeof
#define INF 0x3f3f3f3f
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define inll(x) scanf("%lld", &x)
#define outll(x) printf("%lld", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector
#define pb push_back
#define sz size
#define PII pair<int, int>
#define x first
#define y second
#define P_q priority_queue
#define ft front
#define pf push_front
#define popf pop_front
#define it insert
#define ct count

using namespace std;

const int N = 510, M = 5210;

int n, m1, m2;
int q[N];
int dist[N], cnt[N];
int h[N], e[M], w[M], ne[M], idx;
bool st[N];

void add(int a, int b, int c) {
    e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++ ;
}

bool spfa() {
    mt(dist, 0, szf dist);
    mt(cnt, 0, szf cnt);
    
    int hh = 0, tt = 0;
    flr (i, 1, n) q[tt ++ ] = i, st[i] = true;
    
    while (hh != tt) {
        int t = q[hh ++ ];
        if (hh == N) hh = 0;
        st[t] = false;
        
        fmp(i, t) {
            int j = e[i];
            if (dist[j] > dist[t] + w[i]) {
                dist[j] = dist[t] + w[i];
                cnt[j] = cnt[t] + 1;
                if (cnt[j] >= n) return true;
                
                if (!st[j]) {
                    q[tt ++ ] = j;
                    if (tt == N) tt = 0;
                    st[j] = true;
                }
            }
        }
    }
    
    return false;
}

int main() {
    int T;
	in(T);
	
	while (T -- ) {
	    in(n), in(m1), in(m2);
	    
	    mt(h, -1, szf h);
	    idx = 0;
	    while (m1 -- ) {
	        int a, b, c;
	        in(a), in(b), in(c);
	        add(a, b, c), add(b, a, c);
	    }
	    
	    while (m2 -- ) {
	        int a, b, c;
	        in(a), in(b), in(c);
	        add(a, b, -c);
	    }
	    
	    if (spfa()) puts("YES");
	    else puts("NO");
	}
    
    return 0;
}